refactor bin/setup_heroku so button users get admin accounts

Andrew Cantino 10 years ago
parent
commit
ca0234b02d
2 changed files with 32 additions and 22 deletions
  1. 3 3
      app/views/devise/registrations/new.html.erb
  2. 29 19
      bin/setup_heroku

+ 3 - 3
app/views/devise/registrations/new.html.erb

@@ -15,7 +15,7 @@
15 15
             <ul>
16 16
               <li>Read <a href="https://github.com/cantino/huginn/wiki/Run-Huginn-for-free-on-Heroku" target="_target">this document</a> carefully if you are going to try out Huginn for free on <a href="https://id.heroku.com/" target="_target">Heroku</a>.</li>
17 17
 
18
-              <li>Install the <a href="https://toolbelt.heroku.com/" target="_target">Heroku Toolbelt</a> and run <kbd>heroku login</kbd> if you haven't already.</li>
18
+              <li>Install the <a href="https://toolbelt.heroku.com/" target="_target">Heroku Toolbelt</a> and run <kbd>heroku login</kbd>, if you haven't already.</li>
19 19
 
20 20
               <li>Run the following commands:<br />
21 21
                 <%= content_tag :pre do -%>
@@ -25,7 +25,7 @@ bundle
25 25
 bin/setup_heroku
26 26
 <%- end %>
27 27
 
28
-              <li>Get back to this page and sign up with the invitation code shown by the last command.</li>
28
+              <li>This command will create an admin account for you.</li>
29 29
             </ul>
30 30
           </div>
31 31
           <% end %>
@@ -78,4 +78,4 @@ bin/setup_heroku
78 78
       </div>
79 79
     </div>
80 80
   </div>
81
-</div>
81
+</div>

+ 29 - 19
bin/setup_heroku

@@ -138,19 +138,6 @@ unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASS
138 138
   end
139 139
 end
140 140
 
141
-if first_time
142
-  puts "Restarting..."
143
-  puts capture("heroku restart")
144
-
145
-  puts "Done!"
146
-  puts
147
-  puts "Visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code shown below:"
148
-  puts
149
-  puts "\t#{$config['INVITATION_CODE']}"
150
-
151
-  exit
152
-end
153
-
154 141
 branch = capture("git rev-parse --abbrev-ref HEAD")
155 142
 if yes?("Should I push your current branch (#{branch}) to heroku?")
156 143
   puts "This may take a moment..."
@@ -158,21 +145,44 @@ if yes?("Should I push your current branch (#{branch}) to heroku?")
158 145
 
159 146
   puts "Running database migrations..."
160 147
   puts capture("heroku run rake db:migrate")
148
+end
161 149
 
150
+if first_time
151
+  puts "Restarting..."
152
+  puts capture("heroku restart")
153
+  puts "Done!"
162 154
   puts
163 155
   puts
164 156
   puts "I can make an admin user on your new Huginn instance and setup some example Agents."
165 157
   if yes?("Should I create a new admin user and some example Agents?")
166
-    seed_email = nag "Okay, what is your email address?"
167
-    seed_username = nag "And what username would you like to login as?"
168
-    seed_password = nag "Finally, what password would you like to use?", noecho: true
169
-    puts "\nJust a moment..."
170
-
171
-    capture("heroku run rake db:seed SEED_EMAIL=#{seed_email} SEED_USERNAME=#{seed_username} SEED_PASSWORD=#{seed_password}")
158
+    done = false
159
+    while !done
160
+      seed_email = nag "Okay, what is your email address?"
161
+      seed_username = nag "And what username would you like to login as?"
162
+      seed_password = nag "Finally, what password would you like to use?", noecho: true
163
+      puts "\nJust a moment..."
164
+
165
+      result = capture("heroku run rake db:seed SEED_EMAIL=#{seed_email} SEED_USERNAME=#{seed_username} SEED_PASSWORD=#{seed_password}")
166
+      if result =~ /Validation failed/
167
+        puts "ERROR:"
168
+        puts
169
+        puts result
170
+        puts
171
+      else
172
+        done = true
173
+      end
174
+    end
172 175
     puts
173 176
     puts
174 177
     puts "Okay, you should be all set!  Visit https://#{app_name}.herokuapp.com and login as '#{seed_username}' with your password."
178
+    puts
179
+    puts "If you'd like to make more users, you can visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code:"
180
+  else
181
+    puts
182
+    puts "Visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code shown below:"
175 183
   end
184
+  puts
185
+  puts "\t#{$config['INVITATION_CODE']}"
176 186
 end
177 187
 
178 188
 puts